package com.misty.encryption_decryption.base64;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Base64;

public class Base64Decoder {

    public static String decode(String data) {
        return new String(Base64.getDecoder().decode(data));
    }

    public static byte[] decode(byte[] data) {
        return Base64.getDecoder().decode(data);
    }

    public static void decodeFile(String outPath, String encodedString) {
        File desFile = new File(outPath);
        FileOutputStream fos = null;
        try {
            byte[] decodeBytes = Base64.getDecoder().decode(encodedString);
            fos = new FileOutputStream(desFile);
            fos.write(decodeBytes);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
